﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Specialized;


namespace UILGestion
{

    /// <summary>
    /// Acces au web.config
    /// </summary>
    /// 
    public  static class   Config
    {
        public Config() { }

        public static string LoginModuleDefautPathRoot
        {
            get {return SafeConfigString("appSettings", "LoginPageDefaut", "SodevlogLogin"); }
        }

        public static string PageSecurisee
        {
            get { return SafeConfigString("appSettings", "PageSecurisee", "~/SecurePage.aspx"); }
        }

        public static string LabelLoginViewText
        {
            get { return SafeConfigString("appSettings", "LabelViewNameText", "Login View : "); }
        }

        public static string LabelLoginStatusText
        {
            get { return SafeConfigString("appSettings", "LabelLoginStatusText", "Login Status : "); }
        }

        // Configuration du mail de creation d'un utilisateur
        public static string MailOnUserCreation
        {
            get { return SafeConfigString("appSettings", "mailOnUserCreation", "false"); }
        }
        public static string MailServerSmtp
        {
            get { return SafeConfigString("appSettings", "mailServerSmtp", "smtp.nerim.net"); }
        }
        public static string MailTo
        {
            get { return SafeConfigString("appSettings", "mailTo", "contact@societe.com"); }
        }
        public static string MailSubject
        {
            get { return SafeConfigString("appSettings", "mailSubject", "Création d'un compte"); }
        }
        public static string MailBody
        {
            get { return SafeConfigString("appSettings", "mailBody", "Merci de m'ouvrir un compte"); }
        }
        public static string MailConfirmation
        {
            get { return SafeConfigString("appSettings", "mailConfirmation", "Email de confirmation envoyé"); }
        }
        public static string MailFrom
        {
            get { return SafeConfigString("appSettings", "mailFrom", "contact@societe.com"); }
        }
        public static string SafeConfigString(string configSection, string configKey, string defaultValue)
        {
            NameValueCollection configSettings = ConfigurationSettings.GetConfig(configSection) as NameValueCollection;
            if (configSettings != null)
            {
                string configValue = configSettings[configKey] as string;
                if (configValue != null)
                {
                    return configValue;
                }
            }

            return defaultValue;
        }
    }
}